package com.huawei.java.main;

import com.huawei.java.main.classes.*;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Input {
    private List<Service> services = null;
    private List<Server> servers = null;
    private List<List<Request>> requests = null;

    public static <T> List<T> read(BufferedReader stdin, Creator<T> creator) throws IOException {
        Factory<T> factory = new Factory<>(creator);
        final String line = stdin.readLine();
        final int serverNum = Integer.parseInt(line);
        List<T> list = new ArrayList<>();
        for (int i = 0; i < serverNum; i++) {
            final String describe = stdin.readLine();
            final T item = factory.create(describe);
            list.add(item);
        }
        return list;
    }

    public Input(InputStream stream) {
        try {
            final BufferedReader stdin = new BufferedReader(new InputStreamReader(stream));
            this.servers = read(stdin, new ServerCreator());
            this.services = read(stdin, new ServiceCreator());

            final String line = stdin.readLine();
            final int day = Integer.parseInt(line);
            final List<List<Request>> requestsPerDay = new ArrayList<>();
            for (int i = 0; i < day; i++) {
                final List<Request> requests = read(stdin, new RequestCreator());
                requestsPerDay.add(requests);
            }
            this.requests = requestsPerDay;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public List<Service> getServices() {
        return services;
    }

    public List<Server> getServers() {
        return servers;
    }

    public List<List<Request>> getRequests() {
        return requests;
    }

    public int getDays() {
        return requests.size();
    }
}
